package cn.zyq.demo.system.config.consts.system;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;

@Component
@ConfigurationProperties(prefix = "system")
public class SystemConfig {
    /**
     * 项目path
     */
    public static String projectPath;
    /**
     * 环境差别，dev开发，prod生产，test测试
     */
    public static String env;
    /**
     * 文件在服务器上面的基础路径
     */
    public static String fileBasePath;
    public static String imageMagickPath;
    /**
     * 每秒钟接口最多访问次数
     */
    public static Integer requestLimitTime;
    /**
     * 管理系统最大登录时长，单位：分钟
     */
    public static Long timeoutMgt;
    /**
     * H5系统最大登录时长，单位：天
     */
    public static Long timeoutH5;
    /**
     * 小程序系统最大登录时长，单位：天
     */
    public static Long timeoutMp;
    /**
     * 系统基础包名
     */
    public static String basePackageName;
    /**
     * 系统默认选择的微信配置文件
     */
    public static String serviceCode = "general";

    /**
     * 调试模式开关
     */
    public static Boolean debugMode;

    /**
     *
     */
    public static String fileHostname;

    static {
        try {
            projectPath = new File("").getCanonicalPath();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void setEnv(String env) {
        SystemConfig.env = env;
    }

    public void setFileBasePath(String fileBasePath) {
        if (Env.DEV.equals(env)) {
            SystemConfig.fileBasePath = projectPath + fileBasePath;
        } else {
            SystemConfig.fileBasePath = fileBasePath;
        }
    }

    public void setProjectPath(String projectPath) {
        SystemConfig.projectPath = projectPath;
    }

    public void setRequestLimitTime(Integer requestLimitTime) {
        SystemConfig.requestLimitTime = requestLimitTime;
    }

    public void setImageMagickPath(String imageMagickPath) {
        SystemConfig.imageMagickPath = imageMagickPath;
    }

    public void setTimeoutMgt(Long timeoutMgt) {
        SystemConfig.timeoutMgt = timeoutMgt;
    }

    public void setTimeoutH5(Long timeoutH5) {
        SystemConfig.timeoutH5 = timeoutH5;
    }

    public void setBasePackageName(String basePackageName) {
        SystemConfig.basePackageName = basePackageName;
    }

    public void setServiceCode(String serviceCode) {
        SystemConfig.serviceCode = serviceCode;
    }

    public void setTimeoutMp(Long timeoutMp) {
        SystemConfig.timeoutMp = timeoutMp;
    }

    public void setDebugMode(Boolean debugMode) {
        SystemConfig.debugMode = debugMode;
    }

    public void setFileHostname(String fileHostname) {
        SystemConfig.fileHostname = fileHostname;
    }
}
